package com.example.myapplication.activity.advanced_activity;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

import com.example.myapplication.R;

public class ActivityAlertDialog extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alert_dialog);
        Button alert = findViewById(R.id.btn_alert_dialog);
        DatePicker datePicker = findViewById(R.id.datePicker);
        Button btn_date = findViewById(R.id.btn_get_time);
        TextView textView = findViewById(R.id.textView);
        btn_date.setOnClickListener(v->{
            String date = datePicker.getYear() + "年" + (datePicker.getMonth() + 1) + "月" + datePicker.getDayOfMonth() + "日";
            textView.setText(date);
        });

        alert.setOnClickListener(v->{
            // 创建对话框构建器
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("提示");
            builder.setMessage("是否退出");
            builder.setPositiveButton("确定", (dialog, which) -> System.out.println("确定"));
            builder.setNegativeButton("取消", (dialog, which) -> System.out.println("取消"));
            builder.create().show();
        });
    }
}